package com.example.hasee.zhcd.Adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;


import com.example.hasee.zhcd.R;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by hasee on 2017/9/13.
 */

public class LeavePortEntrustAdapter extends BaseExpandableListAdapter {
    private ArrayList<HashMap<String, String>> list;
    private ArrayList<ArrayList<String>> son_list;
    private Context context;
    private Holder holder;

    public LeavePortEntrustAdapter(Context context, ArrayList<HashMap<String, String>> list, ArrayList<ArrayList<String>> son_list) {
        this.context = context;
        this.list = list;
        this.son_list = son_list;
    }

    @Override
    public int getGroupCount() {
        return list.size();
    }

    @Override
    public int getChildrenCount(int i) {
        return son_list.get(i).size();
    }

    @Override
    public Object getGroup(int i) {
        return list.get(i);
    }

    @Override
    public Object getChild(int i, int i1) {
        return son_list.get(i).get(i1);
    }

    @Override
    public long getGroupId(int i) {
        return 0;
    }

    @Override
    public long getChildId(int i, int i1) {
        return 0;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
        Holder holder;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.leaveportentrust_list_item, null);
            holder = new Holder();
            holder.noticestate = (TextView) view.findViewById(R.id.noticestate);
            holder.entrustevent = (TextView) view.findViewById(R.id.entrustevent);
            holder.noticecontent = (TextView) view.findViewById(R.id.noticecontent);
            holder.noticer = (TextView) view.findViewById(R.id.noticer);
            holder.noticetime = (TextView) view.findViewById(R.id.noticetime);
            view.setTag(holder);
        } else {
            holder = (Holder) view.getTag();
        }
        holder.noticestate.setText((String) list.get(i).get("fzt"));
        holder.entrustevent.setText((String) list.get(i).get("fwtsx"));
        holder.noticecontent.setText((String) list.get(i).get("ftznr"));
        holder.noticer.setText((String) list.get(i).get("fdlr"));
        holder.noticetime.setText((String) list.get(i).get("fdlsj"));
        return view;
    }

    @Override
    public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
        SonHolder sonHolder;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.leaveportentrust_list_item_son, null);
            sonHolder = new SonHolder();
            sonHolder.content = (TextView) view.findViewById(R.id.content);
            view.setTag(sonHolder);
        } else {
            sonHolder = (SonHolder) view.getTag();
        }
        if (son_list.get(i).get(i1).length() == 0) {
            sonHolder.content.setText("暂无通知内容");
        } else {
            sonHolder.content.setText(son_list.get(i).get(i1));
        }

        return view;
    }

    @Override
    public boolean isChildSelectable(int i, int i1) {
        return true;
    }

    class Holder {
        private TextView noticestate;
        private TextView entrustevent;
        private TextView noticecontent;
        private TextView noticer;
        private TextView noticetime;
    }

    class SonHolder {
        private TextView content;
    }
}
